package cn.kgc.springboot03.service.impl;

import cn.kgc.springboot03.entity.Student;
import cn.kgc.springboot03.mapper.StudentMapper;
import cn.kgc.springboot03.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/5/19
 */
@Service
public class StudentServiceImpl implements StudentService {
    private Logger logger = LoggerFactory.getLogger( StudentServiceImpl.class);
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public Student selectById(Integer id) {
        Student student = studentMapper.selectById(id);
        //System.out.println("student = " + student);
        logger.debug("student:"+student); //  all<trace< debug < info < warn < error<fatal< off
        return student;
    }

    @Override
    public List<Student> selectAll() {
        PageHelper.startPage(1, 5);
        List<Student> students = studentMapper.selectAll();
        PageInfo<Student> studentPageInfo = new PageInfo<>(students);
        logger.info("students.size = {}",students.size());
        logger.info("PageInfo ={}",studentPageInfo);
        return students;
    }
}
